import React from "react";
import type { Meta, StoryFn } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import Upload, { IUploadProps, IUploadFile } from "./upload.tsx";

// 默认导出
export default {
    title: 'Upload', // 设置故事的标题
    component: Upload, // 指定组件
    tags: ['autodocs'],
} as Meta;

const defaultFileList: IUploadFile[] = [
    { uid: '123', size: 1234, name: 'hello.md', status: 'uploading', percent: 30 },
    { uid: '122', size: 1234, name: 'xyz.md', status: 'success', percent: 100 },
    { uid: '121', size: 1234, name: 'eyiha.md', status: 'error', percent: 30 }
]

const checkFileSize = (file: File) => {
    if (Math.round(file.size / 1024) > 50) {
        alert("文件过大!");
        return false;
    }
    return true;
}

const filePromise = (file: File) => {
    const newFile = new File([file], "new_name.docx", { type: file.type });
    return Promise.resolve(newFile);
}

const primaryTemplate: StoryFn = (args) => <Upload
    action="https://jsonplaceholder.typicode.com/posts/"
    // action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
    defaultFileList={defaultFileList}
    // beforeUpload={filePromise}
    onChange={action("change")}
    onProgress={action("progress")}
    onSuccess={action("Success")}
    onError={action("Error")}
    name="file_name"
    data={{ "key": "value" }}
    headers={{ "UI-By": "Ydj" }}
    accept=".pdf"
    multiple
    drag
/>;
export const WithPrimary = primaryTemplate.bind({});
WithPrimary.args = {
    children: 'Click me'
};